<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>键盘事件</title>
    <style>
        
    </style>
</head>
<body>
    <div id="root"> </div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

    <script type="text/babel">
        class App extends React.Component{
            render(){
                return <div style={{paddingLeft: '20px'}}>
                        <h2>登录</h2>
                        <form action="">
                            用户名: <input ref={el => this.username = el} type="text" /> <br/>    
                            密　码: <input ref={el => this.password = el} type="password" /> <br />
                            <button onClick={this.login}>登录</button>
                        </form>
                    </div>
            }

            login = (e) => {
                //获取用户名的值
                let user = this.username.value;
                let pass = this.password.value;
                //输出内容
                console.log('当前用户名为'+user +'当前密码为'+pass);
                //阻止默认x行为
                e.preventDefault();
            }
        }

        ReactDOM.render(<App />, document.querySelector("#root"));

    </script>
</body>
</html>